// Automatic loop through all buildings
if (isnil "D_RUNNING_TEST") then { D_RUNNING_TEST = false; };
if (D_RUNNING_TEST) then {
	D_RUNNING_TEST = false;
} else {
	D_RUNNING_TEST = true;
	if (count D_BUILDING_INDEXER > 0) then {
		_current_building = objNull;
		for [{_i = 0},{_i < count D_BUILDING_INDEXER},{_i = _i + 1}] do
		{
			player setDir D_PLAYER_START_DIR;
			player setPos D_PLAYER_START_POS;
			if (!isNull _current_building) then {
				deleteVehicle _current_building;
				sleep 2;
			};
			if (!D_RUNNING_TEST) exitWith { hint "Test Interrupted";};
			_building_type = D_BUILDING_INDEXER select _i;
			_building_pos_infos = D_BUILDING_TABLE select _i;
			if (_building_type isKindof "building") then {
				_current_building = CreateVehicle [_building_type,D_BUILDING_POS, [], 0, "NONE"];
				_current_building setDir random(360);
				sleep 2;
				_type = 0;
				{
					_type_str = switch (_type) do {
						case 1: {"hide"};
						case 2: {"sniper"};
						default {"intern"};
					};
					if (!D_RUNNING_TEST) exitWith {};
					_building_pos_types = +_x;
					If (count _building_pos_types > 0) then {
						{
							if (!D_RUNNING_TEST) exitWith {};
							_pos_info = +_x;
							_pos = _pos_info select 0; 
							_angle = _pos_info select 1;
							_angle = _angle + getDir _current_building;
							_position = [getPosAsl _current_building, getDir _current_building, _pos] call XfBuildingPositionCalculator;
							player sideChat Format["Moving To: %1 => %2 => %3",_type_str, _pos_info, _position];
							sleep 1;
							player setDir _angle;
							player setPosAsl _position;
							sleep 3;
						} foreach _building_pos_types;
					};
					_type = _type + 1;
				} foreach _building_pos_infos;
			} else {
				hint format["Unknown Building: %1",_building_type];
				sleep 3;
			};
		};
	};
	D_RUNNING_TEST = false;
};
